package com.atguigu.gmall.cart.service;

import com.atguigu.gmall.cart.mapper.CartMapper;
import com.atguigu.gmall.cart.pojo.Cart;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

@Service
public class CartServiceAsync {

    @Autowired
    CartMapper cartMapper;

    @Async
    public void updateCountBySkuIdAndUserId(String userId, Long skuId, Cart cart) {
        cartMapper.update(cart,new UpdateWrapper<Cart>().eq("user_id",userId).eq("sku_id",skuId));
    }

    @Async
    public void insertByUserId( Cart cart) {
        cartMapper.insert(cart);
    }


    public void delete(String userKey) {
        cartMapper.delete(new QueryWrapper<Cart>().eq("user_id",userKey));
    }
}
